<?php
	
	// Integrimi i skedave sistemore
    include('../include/functions.inc.php');
	include('../include/template.class.php');
	
	
	// DB CONNECT
	dbOpen("dielli");
	
	
	// PROJECT
	$PROJECT = setProject();
	
	
	// Ndyshoret primare
	define('TPL','../include/styles/'.$PROJECT['style'].'/dielli/links.html');
	define('FILENAME',basename($_SERVER["PHP_SELF"]));
	
	
	// TMP CLASS
	$tmp = new Template(TPL,$PROJECT['lang']);
	
	
	// SPLASH SCREEN
	if (isset($_GET['splash'])) 
		splash($_GET['splash'], "../dielli/links.php");
	
		
	// MENUES
	$tmp->setContent("CATEGORY",$tmp->menu("category","../dielli"));
	$tmp->setContent("DIELLI",$tmp->menu("dielli",FILENAME));
	$tmp->setContent("FOOTMENU",$tmp->menu("foot"));
	
	
	$tmp->setContent("NEWS",news("dielli"));
	$tmp->setContent("RANDOM",randomContent("dielli"));
	
	
	if (isset($_POST['link'])) {
		
		if (empty($_POST['linkname']))
			$ERROR['linkname'] = "null";
		
		if (empty($_POST['link']))
			$ERROR['link'] = "null";
			
		if (empty($_POST['description']))
			$ERROR['linkdescript'] = "null";
			
		if (empty($_POST['name']))
			$ERROR['name'] = "null";
		elseif(!eregi("^[a-zA-Z]+[[:space:]]+[a-zA-Z]{2,20}$",$_POST['name'])) 
			$ERROR['name'] = "syntax";
			
		if (empty($ERROR)) {
			
			mysql_query("INSERT INTO links SET 
							linkname = '".$_POST['linkname']."', 
							link = '".$_POST['link']."', 
							description = '".$_POST['description']."',
							regdate = '".$_SERVER['REQUEST_TIME']."',
							name = '".$_POST['name']."'
						");
			
			// Rilexo faqen me porosin per sukses
			header("Location: links.php?splash=sendlink"); 
			exit;
		}
	}
	
	
	// Te gjitha komentet per librin 
	$query = mysql_query("SELECT * FROM links WHERE access = '1' ORDER BY regdate DESC");
	
	if (mysql_num_rows($query) > 0) {
		
		while ($ROW = mysql_fetch_assoc($query)) {
			
			// Fusha me te dhenat e komenteve
			$LINKS[] = $ROW;
		}
		
		// Zevendeso vlerat
		$tmp->setContent("LINKS",$LINKS);
	}
	else 
		// Fshije bllokun e porosis
		$tmp->setContent("LINKS",array());
		
	
	// Help text
	$tmp->setContent("HELP",$tmp->xmlContent('sendlink',"help.xml"));	
	
	// LABELS
	$tmp->setLabels();
	
	
	// Convert POST and ERROR vars in Form
	$tmp->setForm($_POST,$ERROR);
	
	
	// DISPLAY ALL						  
	echo $tmp->vorlage;
?>